﻿using System;
using System.Linq;
using System.Xml.Linq;

namespace _133_修改XML元素的内容
{
    class Program
    {
        static void Main(string[] args)
        {

            //定义一个XML元素的内容
            XElement xml文档 = new XElement("Productions",
                new XElement("Product",
                new XElement("id", 1201),
                new XElement("desc", "产品 A"),
                new XElement("mode", 7)),
                new XElement("Product",
                new XElement("id", 1202),
                new XElement("desc", "产品B"),
                new XElement("mode", 3)));

            Console.WriteLine("-----未替换XML：----------");
            Console.WriteLine("aaaaa,{0}",xml文档);

            var 查询 = from x in xml文档.Elements()
                     where (int)x.Element("mode") == 3
                     select x;

            if (查询.Count()>0)
            {
                XElement e = 查询.First();
                e.Element("desc").Value = "产品G";
            }

            Console.WriteLine("\n-----------替换后：---------------");
            Console.WriteLine(xml文档);
        }
    }
}
